package com.nstar.countdown.view.components
{
	import com.nstar.base.util.DateUtils;
	
	import flash.utils.clearInterval;
	import flash.utils.setInterval;
	
	import mx.controls.Label;
	import mx.events.FlexEvent;

	public class TimeLabel extends Label
	{
		private var interval:uint = 0;
		public var showWeek:Boolean = false;
		
		public function TimeLabel()
		{
			super();
			this.addEventListener(FlexEvent.CREATION_COMPLETE,init);
		}
		
		private function init(event:FlexEvent):void{
			start();
		}
		
		private function getNow():void{
			var now:String = DateUtils.format(new Date(),"YYYY-MM-DD HH:MS:SS");
			if(showWeek){
				now += " "+DateUtils.week();
			}
			this.text = now
		}
		
		public function start():void{
			interval = setInterval(getNow,1000);
		}
		
		public function stop():void{
			clearInterval(interval);
		}
	}
}